<template>
  <div id="app">
    <div id="nav">
      <router-link to="/">首页</router-link>
      <router-link style="margin-right: 1rem;" to='#' @click.native="See('https://sanghongxv.gitee.io/document/picturehost.html')">关于</router-link>
      <el-dropdown v-if="$store.state.login"  @command="logOut">
       <el-avatar shape="square" class="avater" :src="avatar"></el-avatar>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click="logOut">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <transition >
      <router-view/>
    </transition>
  </div>
</template>
<script>
export default {
  data() {
    return{
      transitionName: '',
      colorAsh:false,
      avater:''
    }
  },
  watch: {
	'$route' (to, from) {
      const routeDeep = ['/', '/about','/private','/public','/configure'];
      const toDepth = routeDeep.indexOf(to.path)
      const fromDepth = routeDeep.indexOf(from.path)
      this.transitionName = toDepth < fromDepth ? 'slide-right' : 'slide-left';
    }
  },
  created() {
    //在页面加载时读取sessionStorage里的状态信息
    if (localStorage.getItem("store")) {
      this.$store.replaceState(
        Object.assign(
          {},
          this.$store.state,
          JSON.parse(localStorage.getItem("store"))
        )
      );
      this.avatar = this.$store.state.avatar
    }
    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener("beforeunload", () => {
      localStorage.setItem("store", "");
      localStorage.setItem("store", JSON.stringify(this.$store.state));
    });
  },
  methods:{
    logOut() {
      localStorage.clear()
      this.$store.dispatch('LogOut')
      this.$router.push('/')
    },
    See(e){
      window.open(e,'_blank');
    }
  }
}
</script>
<style lang="scss">
*{
  margin: 0;
  padding: 0;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  padding-top: 3.875rem;
}

#nav {
  position: fixed;
  top: 0;
  right: 3.5rem;
  z-index: 0;
  height: 3.875rem;
  line-height: 3.875rem;
  .el-dropdown {
    position: absolute;
    top: .6rem;
    height: 2.4rem;
  }
  a {
    font-size: 1.25rem;
    color: #2c3e50;
    margin-left: 1.25rem;
    text-decoration:none;
    &.router-link-exact-active {
      color: #42b983;
    }
  }
}

.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  will-change: transform;
  transition: all 1000ms;
  position: absolute;
}
 
.slide-right-enter {
  opacity: 0;
  transform: translateX(-150%);
}
 
.slide-right-leave-active {
  opacity: 0;
  transform: translateX(100%);
}
 
.slide-left-enter {
  opacity: 0;
  transform: translateX(150%);
}
.slide-left-leave-active {
  opacity: 0;
  transform: translateX(-100%);
}
.illustration{
  position: absolute;
  width:37.5rem;
  opacity: 0.8;
}
</style>
